/**
 * 用户相关API接口
 */

import { request } from '@/utils/request';

// 类型定义
export interface User {
  username: string;
  password: string;
  email: string;
}

export interface UserDTO {
  id: number;
  createTime: string;
  updateTime: string;
  username: string;
  email: string;
}

// 获取用户列表
export async function getAllUsers(): Promise<UserDTO[]> {
  return request.get('/api/users/list');
}

// 根据ID获取用户
export async function getUserById(id: number): Promise<UserDTO> {
  return request.get('/api/users/get', { params: { id } });
}

// 根据用户名获取用户
export async function getUserByUsername(username: string): Promise<UserDTO> {
  return request.get('/api/users/username', { params: { username } });
}

// 创建用户
export async function createUser(data: User): Promise<UserDTO> {
  return request.post('/api/users/create', data);
}

// 更新用户
export async function updateUser(id: number, data: User): Promise<UserDTO> {
  return request.put(`/api/users/update?id=${id}`, data);
}

// 删除用户
export async function deleteUser(id: number): Promise<void> {
  return request.delete('/api/users/delete', { params: { id } });
}